<?php
include("../include/header.inc.php");

include('../Include/functions.inc.php');
?>
<div data-role="page" id="home">
    <!-- Header -->
    <?php
       include("../Include/banner.inc.php")
    ?>

    <div data-role="content">
        
        <?php
            
            $nom = '';
            $prenom = '';
            $email = '';
            
            if(isset($_GET) && count($_GET) > 0){
                $id = $_GET['id'];
            }
            
            if(isset($_POST) && count($_POST) > 0){
                
                if(!isset($id)){
                    $id = $_POST['id'];
                }
                
                if(empty($_POST['nomParticipant'])){
                    echo "<strong>". $textes['saisir_nom'][$_COOKIE['lang']] ."</strong>";
                }
                elseif(empty($_POST['prenomParticipant'])){
                 
                      echo "<strong>". $textes['saisir_prenom'][$_COOKIE['lang']] ."</strong>";
                }
                elseif(empty($_POST['emailParticipant'])){
                       echo "<strong>". $textes['saisir_email'][$_COOKIE['lang']] ."</strong>";
                    
                }
                else{
                    $email = $_POST['emailParticipant'];
                    
                    $result = checkRevote($email);
                    
                    $nb = mysql_fetch_array($result);
                    if($nb[0] == 0){
                        //Ajouter le vote dans la base de données
                        InsertNouveauVote($_POST['nomParticipant'], $_POST['prenomParticipant'], $email, $id);

                        echo "<script>";
                      
                         echo "alert(".$textes['vote_ok'][$_COOKIE['lang']].")";
                       
                        echo "</script>";
                    }
                    else{
                       echo "<script>";
                        echo "alert(".$textes['vote_twice'][$_COOKIE['lang']].")";
                        echo "alert('Vous ne pouvez voter que pour une seule vidéo!')";
                        echo "</script>"; 
                    }
                    
                    $prenom = $_POST['prenomParticipant'];
                    $nom = $_POST['nomParticipant'];
                }
                
            }
        ?>
        
        <form method="post" target="_self">
            <input type="hidden" name="id" value="<?PHP echo $id; ?>" />
            Nom: <input type="text" name="nomParticipant" value="<?PHP echo $nom; ?>"/>
            Prenom: <input type="text" name="prenomParticipant" value="<?PHP echo $prenom; ?>" />
            Email: <input type="email" name="emailParticipant" value="<?PHP echo $email; ?>"/>
            
            <input type="submit" name="sendForm" value="Voter" />
        </form>
        
        
    </div>
        <!-- Footer -->
    <?php
    include("../Include/footer.inc.php")
    ?>
</div>